// const moment = require('moment');
const path = require('path');
const Mock = require('mockjs');
const fileUtil = require("../../src/util/fileUtil")


// req.param 是一个函数。
/*
function param(name, defaultValue) {
  var params = this.params || {};
  var body = this.body || {};
  var query = this.query || {};

  var args = arguments.length === 1
    ? 'name'
    : 'name, default';
  deprecate('req.param(' + args + '): Use req.params, req.body, or req.query instead');

  if (null != params[name] && params.hasOwnProperty(name)) return params[name];
  if (null != body[name]) return body[name];
  if (null != query[name]) return query[name];

  return defaultValue;
}
*/

module.exports = function (app) {
  // 监听请求
  app.get(process.env.VUE_APP_BASE_API_CONTEXT + '/admin/infos', function (req, res) {
    console.log("mock\\test\\admin.js req.data", req.data)
    console.log("mock\\test\\admin.js req.body", req.body)
    console.log("mock\\test\\admin.js req.params", req.params)
    console.log("mock\\test\\admin.js req.query", req.query)
    console.log("")
    console.log("")
    var jsonObj = fileUtil.getJson5File(path.join(__dirname, './admin.json5'));
    res.json({
      code: 20000,
      message: 'success',
      source: 'test',
      data: Mock.mock(jsonObj)
    });
  });

  // 接收单个 id
  app.get(process.env.VUE_APP_BASE_API_CONTEXT + '/admin/info', function (req, res) {
    console.log("mock\\test\\admin.js req.data", req.data)
    console.log("mock\\test\\admin.js req.body", req.body)
    console.log("mock\\test\\admin.js req.params", req.params)
    console.log("mock\\test\\admin.js req.query", req.query)
    console.log("")
    console.log("")
    var jsonObj = fileUtil.getJson5File(path.join(__dirname, './admin.json5'));
    res.json({
      code: 20000,
      message: 'success',
      source: 'test',
      data: Mock.mock(jsonObj)
    });
  });

  app.get(process.env.VUE_APP_BASE_API_CONTEXT + '/admin/info1/:box', function (req, res) {
    console.log("mock\\test\\admin.js req.data", req.data)
    console.log("mock\\test\\admin.js req.body", req.body)
    console.log("mock\\test\\admin.js req.params", req.params)
    console.log("mock\\test\\admin.js req.query", req.query)
    console.log("")
    console.log("")
    var jsonObj = fileUtil.getJson5File(path.join(__dirname, './admin.json5'));
    res.json({
      code: 20000,
      message: 'success',
      source: 'test',
      data: Mock.mock(jsonObj)
    });
  });

  // 接收对象
  app.get(process.env.VUE_APP_BASE_API_CONTEXT + '/admin/info2', function (req, res) {
    console.log("mock\\test\\admin.js req.data", req.data)
    console.log("mock\\test\\admin.js req.body", req.body)
    console.log("mock\\test\\admin.js req.params", req.params)
    console.log("mock\\test\\admin.js req.query", req.query)
    console.log("")
    console.log("")
    var jsonObj = fileUtil.getJson5File(path.join(__dirname, './admin.json5'));
    res.json({
      code: 20000,
      message: 'success',
      source: 'test',
      data: Mock.mock(jsonObj)
    });
  });

  // 接收单个 id
  app.post(process.env.VUE_APP_BASE_API_CONTEXT + '/admin/info3', function (req, res) {
    console.log("mock\\test\\admin.js req.data", req.data)
    console.log("mock\\test\\admin.js req.body", req.body)
    console.log("mock\\test\\admin.js req.params", req.params)
    console.log("mock\\test\\admin.js req.query", req.query)
    console.log("")
    console.log("")
    var jsonObj = fileUtil.getJson5File(path.join(__dirname, './admin.json5'));
    res.json({
      code: 20000,
      message: 'success',
      source: 'test',
      data: Mock.mock(jsonObj)
    });
  });

  // 接收对象
  app.post(process.env.VUE_APP_BASE_API_CONTEXT + '/admin/info4', function (req, res) {
    console.log("mock\\test\\admin.js req.data", req.data)
    console.log("mock\\test\\admin.js req.body", req.body)
    console.log("mock\\test\\admin.js req.params", req.params)
    console.log("mock\\test\\admin.js req.query", req.query)
    console.log("")
    console.log("")
    var jsonObj = fileUtil.getJson5File(path.join(__dirname, './admin.json5'));
    res.json({
      code: 20000,
      message: 'success',
      source: 'test',
      data: Mock.mock(jsonObj)
    });
  });
}
